package sng.modules.view.components.city.logic.unit
{
	import com.tencent.animator.view.AnimatorCollection;
	
	import core.interfaces.IDispose;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	import sng.modules.view.components.city.logic.City;
	import sng.modules.view.components.city.logic.movement.AIMove;
	import sng.modules.view.components.city.logic.movement.Wander;

	//Create By royjin 20110706
	//可以移动的人物,汽车等管理容器
	public final class MoveCharManager extends Object implements IDispose
	{
		private var city:City;
		private var moveCharCollection:Array = new Array();
		
		public function MoveCharManager(_city:City)
		{
			city = _city;	
			this.RandomAddChar();
		}
		public function dispose():void
		{
			for each(var i:MoveChar in moveCharCollection)
			{
				i.dispose();
			}
			city.cityView.groundScene.removeTile(i);
		}
		private function RandomAddChar():void
		{
			for(var i:int=0;i<2;i++)
			{
				var moveChar:MoveChar = new MoveChar(this.city.cityView);
				moveCharCollection.push(moveChar);
				
				moveChar.addEventListener(flash.events.Event.COMPLETE,OnLoadComplete,false,0,true);
				moveChar.LoadSkin("assets/dat/0001.dat");
			}
			
		}
		
		protected function OnLoadComplete(event:Event):void
		{
			var mc:MoveChar = event.target as MoveChar;
			mc.removeEventListener(flash.events.Event.COMPLETE,OnLoadComplete);
			
			var rd:Array = city.cityView.astarGrid.getWalkables();
			if(rd.length>0)
			{
				var id:int = Math.random()*rd.length;
				city.cityView.groundScene.addTile(mc,100,100,city.cityView,true);
				mc.x = rd[id].column*City.GRID_CELLSIZE;
				mc.y = rd[id].row*City.GRID_CELLSIZE;
				mc.setSize(0,0,1);

				
				mc.moveBehavior = new Wander(2000);
				mc.moveBehavior.execute();
			}
		}
	}
}